package com.example.sprintbootarithmetic.arithmeic;


public class InsertValuesearch {
    public static void main(String[] args) {
        int[] arr = new int[100];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = i + 1;
        }
        int retval = InsertValuesearch(0, arr.length - 1, arr, 23);
        System.out.println(retval);
    }

    public static int InsertValuesearch(int left, int right, int[] arr, int findval) {
        System.out.println("插值查找");
        if (left > right || findval < arr[left] || findval > arr[arr.length - 1]) {
            return -1;
        }
        int findmid = left + (right + left) * (findval - arr[left]) / (arr[right] - arr[left]);
        if (findval > arr[findmid]) {
            InsertValuesearch(left, findmid + 1, arr, findval);
        } else if (findval < arr[findmid]) {
            InsertValuesearch(findmid - 1, right, arr, findval);
        }
        return findmid;
    }
}
